/**
 * Created by shudong.msd(风骐) on 2016/4/28.
 */

'use strict';

app.factory('indexSearchService',function(){

    var service = {};

    service.formatWeekDate = function(strdate){
        var tmpStarts = strdate.split('~');
        tmpStarts[0] = new Date(tmpStarts[0]);
        var tmpStartYear = tmpStarts[0].getFullYear();
        tmpStarts[1] = new Date(tmpStartYear+'/'+tmpStarts[1]);
        if(tmpStarts[1].getTime()<tmpStarts[0].getTime()){
            tmpStarts[1] = new Date(tmpStarts[1].getFullYear()+1,tmpStarts[1].getMonth(),tmpStarts[1].getDate());
        }
        return tmpStarts[0].Format("yyyyMMdd")+'-'+tmpStarts[1].Format("yyyyMMdd");
    };


    service.proFormDetail = function(scope,queryType){
        if(scope.formData['startTime'].indexOf('~')>=0){
            scope.formData['isWeek'] = 1;//周
            scope.formData['startTime'] = service.formatWeekDate(scope.formData['startTime']);
            scope.formData['endTime'] = service.formatWeekDate(scope.formData['endTime']);

        }else{
            scope.formData['isWeek'] = 0;
            scope.formData['startTime'] = new Date(scope.formData['startTime']).Format("yyyyMMdd");
            scope.formData['endTime'] = new Date(scope.formData['endTime']).Format("yyyyMMdd");
        }

        scope.formData['queryType'] = queryType;

        var keywords = [];
        for(var i in scope.search_tags){
            keywords.push(scope.search_tags[i].id);
        }
        if(queryType==4||queryType==5){
            scope.formData['star'] = keywords;
        }else{
            scope.formData['programme'] = keywords;
        }
        scope.formData['pageNo'] = 1;
        scope.formData['pageSize'] = 50;

        //产生uuid
        scope.formData['uuid'] = generateUUID();

    };

    return service;

});